package com.ltkj.shop.service.impl;

import java.util.List;

import com.ltkj.common.core.constant.UserConstants;
import com.ltkj.common.core.utils.DateUtils;
import com.ltkj.common.security.utils.SecurityUtils;
import com.ltkj.shop.mapper.ShopGoodsCategoryBizMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ltkj.shop.mapper.ShopGoodsCategoryMapper;
import com.ltkj.shop.domain.ShopGoodsCategory;
import com.ltkj.shop.service.IShopGoodsCategoryService;

/**
 * 文创商品类别Service业务层处理
 * 
 * @author xupf
 * @date 2023-08-29
 */
@Service
public class ShopGoodsCategoryServiceImpl implements IShopGoodsCategoryService 
{
    @Autowired
    private ShopGoodsCategoryMapper shopGoodsCategoryMapper;
    @Autowired
    private ShopGoodsCategoryBizMapper shopGoodsCategoryBizMapper;

    /**
     * 查询文创商品类别
     * 
     * @param id 文创商品类别主键
     * @return 文创商品类别
     */
    @Override
    public ShopGoodsCategory selectShopGoodsCategoryById(Long id)
    {
        return shopGoodsCategoryMapper.selectShopGoodsCategoryById(id);
    }

    /**
     * 查询文创商品类别列表
     * 
     * @param shopGoodsCategory 文创商品类别
     * @return 文创商品类别
     */
    @Override
    public List<ShopGoodsCategory> selectShopGoodsCategoryList(ShopGoodsCategory shopGoodsCategory)
    {
        return shopGoodsCategoryBizMapper.selectShopGoodsCategoryList(shopGoodsCategory);
    }

    /**
     * 新增文创商品类别
     * 
     * @param shopGoodsCategory 文创商品类别
     * @return 结果
     */
    @Override
    public int insertShopGoodsCategory(ShopGoodsCategory shopGoodsCategory)
    {
        shopGoodsCategory.setCreateTime(DateUtils.getNowDate());
        shopGoodsCategory.setCreateBy(SecurityUtils.getLoginUser().getUsername());
        shopGoodsCategory.setIsDel("0");
        return shopGoodsCategoryMapper.insertShopGoodsCategory(shopGoodsCategory);
    }

    /**
     * 修改文创商品类别
     * 
     * @param shopGoodsCategory 文创商品类别
     * @return 结果
     */
    @Override
    public int updateShopGoodsCategory(ShopGoodsCategory shopGoodsCategory)
    {
        shopGoodsCategory.setUpdateTime(DateUtils.getNowDate());
        shopGoodsCategory.setUpdateBy(SecurityUtils.getLoginUser().getUsername());
        return shopGoodsCategoryMapper.updateShopGoodsCategory(shopGoodsCategory);
    }

    /**
     * 批量删除文创商品类别
     * 
     * @param ids 需要删除的文创商品类别主键
     * @return 结果
     */
    @Override
    public int deleteShopGoodsCategoryByIds(Long[] ids)
    {
        return shopGoodsCategoryBizMapper.deleteShopGoodsCategoryByIds(ids);
    }

    /**
     * 删除文创商品类别信息
     * 
     * @param id 文创商品类别主键
     * @return 结果
     */
    @Override
    public int deleteShopGoodsCategoryById(Long id)
    {
        return shopGoodsCategoryBizMapper.deleteShopGoodsCategoryById(id);
    }

    /**
     * 是否存在类别子节点
     *
     * @param id 类别ID
     * @return 结果
     */
    @Override
    public boolean hasChildById(Long id)
    {
        int result = shopGoodsCategoryBizMapper.hasChildById(id);
        return result > 0;
    }
}
